﻿package mortal.game.view.common.tooltip.tooltips
{
    import Message.DB.Tables.*;
    import __AS3__.vec.*;
    import com.mui.controls.*;
    import com.mui.display.*;
    import com.mui.utils.*;
    import extend.language.*;
    import flash.text.*;
    import flash.utils.*;
    import mortal.common.*;
    import mortal.common.global.*;
    import mortal.game.cache.*;
    import mortal.game.resource.*;
    import mortal.game.resource.info.item.*;
    import mortal.game.resource.tableConfig.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.display.*;
    import mortal.game.view.common.item.*;
    import mortal.game.view.common.tooltip.*;
    import mortal.game.view.common.tooltip.tooltips.base.*;
    import mortal.game.view.medal.*;

    public class TooltipMedal extends ToolTipScaleBg
    {
        private var _icon:BaseItem;
        private var _txtName:GTextFiled;
        private var _des:GTextFiled;
        private var _medalNum:GTextFiled;
        private var _noPrivilegeTxt:GTextFiled;
        private var _bmpZDL:GBitmap;
        private var _spliteLine:ScaleBitmap;
        private var _bmpFight:BitmapNumberText;
        private var _attrPart:GSprite;
        private var _privilegePart:GSprite;
        private var _medalPart:GSprite;
        private var _medalLvIcon:GImageBitmap;
        private var _medalLevel:BitmapNumberText;
        private var _info:TMedal;
        private var _vcAttributeNameText:Vector.<GTextFiled>;
        private var _vcAttributeValueText:Vector.<BitmapNumberText>;
        private var _vcPrivilegeTxt:Vector.<GTextFiled>;
        private var _medalTxt:Vector.<GTextFiled>;

        public function TooltipMedal()
        {
            this._vcAttributeNameText = new Vector.<GTextFiled>;
            this._vcAttributeValueText = new Vector.<BitmapNumberText>;
            this._vcPrivilegeTxt = new Vector.<GTextFiled>;
            this._medalTxt = new Vector.<GTextFiled>;
            this.createChildren();
            return;
        }// end function

        public function createChildren() : void
        {
            this.paddingBottom = 10;
            var _loc_4:int = 10;
            this.paddingRight = 10;
            this.paddingLeft = _loc_4;
            this._attrPart = UICompomentPool.getUICompoment(GSprite);
            this._attrPart.y = 110;
            this.addChild(this._attrPart);
            this._privilegePart = UICompomentPool.getUICompoment(GSprite);
            this.addChild(this._privilegePart);
            this._medalPart = UICompomentPool.getUICompoment(GSprite);
            this.addChild(this._medalPart);
            var _loc_1:* = GlobalStyle.textFormatPutong;
            _loc_1.align = TextFormatAlign.CENTER;
            _loc_1.size = 14;
            _loc_1.bold = true;
            this._txtName = UIFactory.gTextField("", 9, 0, 220, 25, this, _loc_1);
            this._des = UIFactory.gTextField("", 85, 56, 130, 50, this, GlobalStyle.textFormatHuang2);
            this._des.wordWrap = true;
            this._des.multiline = true;
            this._medalNum = UIFactory.gTextField("", 9, 0, 220, 25, this._medalPart, GlobalStyle.textFormatHuang2.center());
            this._spliteLine = UIFactory.bg(9, 220, 220, 2, this._privilegePart, ImagesConst.SplitLine);
            this._noPrivilegeTxt = UIFactory.gTextField(Language.getString(21385), 9, 10, 220, 25, this._privilegePart, _loc_1);
            this._icon = UICompomentPool.getUICompoment(BaseItem);
            this._icon.x = 5;
            this._icon.y = 26;
            this._icon.setItemStyle(ItemStyleConst.Big, ImagesConst.ShopItemBg, 6, 6);
            this.addChild(this._icon);
            this._bmpZDL = UIFactory.gBitmap(ImagesConst.ToolTipCombat, 84, 30, contentContainer2D);
            this._bmpFight = UIFactory.bitmapNumberText(127, 30, "EquipToolTipCombat.png", 14, 16, -2, contentContainer2D, 10);
            UIFactory.gImageBitmap(ImagesConst.medalWinTxt_4, 72, -4, this._attrPart);
            UIFactory.gImageBitmap(ImagesConst.medalWinTxt_5, 71, -4, this._privilegePart);
            var _loc_2:* = UIFactory.gBitmap(ImagesConst.GroupCopySide, 0, 0, this._attrPart);
            var _loc_3:* = UIFactory.gBitmap(ImagesConst.GroupCopySide, 230, 0, this._attrPart);
            _loc_3.scaleX = -1;
            _loc_2 = UIFactory.gBitmap(ImagesConst.GroupCopySide, 0, 0, this._privilegePart);
            _loc_3 = UIFactory.gBitmap(ImagesConst.GroupCopySide, 230, 0, this._privilegePart);
            _loc_3.scaleX = -1;
            this._medalLvIcon = UIFactory.gImageBitmap(ImagesConst.challengeCopyNewTxt_11, 35, 74, this);
            this._medalLevel = UIFactory.bitmapNumberText(60, 74, "FightInfoNum.png", 12, 15, -1, this);
            return;
        }// end function

        override public function set data(param1) : void
        {
            if (param1 is TMedal)
            {
                this._info = param1 as TMedal;
            }
            else if (param1 is ItemData)
            {
                this._info = MedalConfig.instance.getTmedalByCode((param1 as ItemData).itemInfo.effect);
            }
            this._medalLevel.text = "" + this._info.typeLevel;
            setBg(ToolTipUtil.getBgNameByColor(this._info.catagoryLevel));
            this._icon.source = MedalUtil.getMedalIconUrlByTmedal(this._info, 1);
            this._txtName.htmlText = MedalUtil.getMedalNameByTmedal(this._info) + "(Lv." + this._info.typeLevel + ")";
            this._bmpFight.text = int(MedalUtil.getCombatByTmedal(this._info)).toString();
            this._des.text = this._info.desc;
            this._medalNum.text = Language.getStringByParam(20810, ChallengeCopyConfig.instance.getTchallengeByMedalCode(this._info.code).towerName, Cache.instance.medal.getCurrentCatagoryMedalNum(this._info.catagory));
            this.updateAttrList();
            this.updatePrivilege();
            this.updateMedalList();
            this.updatePos();
            super.data = param1;
            return;
        }// end function

        private function updatePos() : void
        {
            if (this._vcPrivilegeTxt.length)
            {
                this._spliteLine.y = this._vcPrivilegeTxt.length * 25 + 20;
            }
            else
            {
                this._spliteLine.y = this._noPrivilegeTxt.y + this._noPrivilegeTxt.textHeight + 6;
            }
            this._privilegePart.y = this._attrPart.y + this._attrPart.height + 8;
            this._medalPart.y = this._privilegePart.y + this._privilegePart.height + 5;
            return;
        }// end function

        private function clearAttrList() : void
        {
            var _loc_1:GTextFiled = null;
            var _loc_2:BitmapNumberText = null;
            for each (_loc_1 in this._vcAttributeNameText)
            {
                
                _loc_1.dispose(true);
            }
            for each (_loc_2 in this._vcAttributeValueText)
            {
                
                _loc_2.dispose(true);
            }
            this._vcAttributeNameText.length = 0;
            this._vcAttributeValueText.length = 0;
            return;
        }// end function

        private function clearMedalList() : void
        {
            var _loc_1:GTextFiled = null;
            for each (_loc_1 in this._medalTxt)
            {
                
                _loc_1.dispose(true);
            }
            this._medalTxt.length = 0;
            return;
        }// end function

        private function updateAttrList() : void
        {
            var _loc_3:GTextFiled = null;
            var _loc_4:BitmapNumberText = null;
            var _loc_5:int = 0;
            var _loc_6:int = 0;
            this.clearAttrList();
            var _loc_1:* = GlobalStyle.textFormatAnHuan;
            _loc_1.size = 12;
            var _loc_2:* = MountConfig.instance.attribute;
            var _loc_7:int = 0;
            while (_loc_7 < _loc_2.length)
            {
                
                _loc_5 = this._info[_loc_2[_loc_7]];
                if (_loc_5)
                {
                    _loc_3 = UIFactory.gTextField(GameDefConfig.instance.getAttributeName2(_loc_2[_loc_7]), 15 + _loc_6 % 2 * 104, 12 * (_loc_6 - _loc_6 % 2) + 16, 55, 20, this._attrPart, _loc_1);
                    this._vcAttributeNameText.push(_loc_3);
                    _loc_4 = UIFactory.bitmapNumberText(60 + _loc_6 % 2 * 104, 12 * (_loc_6 - _loc_6 % 2) + 21, "RoleInfoNum.png", 8, 10, -1, this._attrPart, 14);
                    _loc_4.text = _loc_5.toString();
                    this._vcAttributeValueText.push(_loc_4);
                    _loc_6++;
                }
                _loc_7++;
            }
            return;
        }// end function

        private function updateMedalList() : void
        {
            var _loc_2:GTextFiled = null;
            var _loc_4:String = null;
            var _loc_5:TMedal = null;
            var _loc_6:int = 0;
            this.clearMedalList();
            var _loc_1:* = MedalConfig.instance.getMedCatagoryArrByCatagory(this._info.catagory);
            var _loc_3:* = GlobalStyle.textFormatBai.left();
            while (_loc_6 < 4)
            {
                
                _loc_5 = _loc_1[(_loc_6 + 1)][0];
                _loc_2 = UIFactory.gTextField("", 5, 23 * _loc_6 + this._medalNum.y + this._medalNum.textHeight + 10, 225, 30, this._medalPart, _loc_3);
                if (Cache.instance.medal.getOwnMedalByCatagoryAndType(_loc_5.catagory, _loc_5.code))
                {
                    _loc_4 = Language.getString(20811);
                    _loc_5 = Cache.instance.medal.getOwnMedalByCatagoryAndType(_loc_5.catagory, _loc_5.code);
                    _loc_2.htmlText = MedalUtil.getMedalNameByTmedal(_loc_5) + _loc_4;
                }
                else
                {
                    _loc_4 = Language.getStringByParam(20812, ChallengeCopyConfig.instance.getTchallengeByMedalCode(_loc_5.code).levelName);
                    _loc_2.htmlText = MedalUtil.getMedalNameByTmedal(_loc_1[(_loc_6 + 1)][0] as TMedal) + _loc_4;
                }
                this._medalTxt.push(_loc_2);
                _loc_6++;
            }
            return;
        }// end function

        private function clearPrivilegeTxt() : void
        {
            var _loc_1:GTextFiled = null;
            for each (_loc_1 in this._vcPrivilegeTxt)
            {
                
                _loc_1.dispose(true);
            }
            this._vcPrivilegeTxt.length = 0;
            return;
        }// end function

        private function updatePrivilege() : void
        {
            var _loc_2:GTextFiled = null;
            var _loc_3:int = 0;
            var _loc_5:int = 0;
            var _loc_6:int = 0;
            this.clearPrivilegeTxt();
            var _loc_1:* = MedalConfig.instance.addPrivilegeArr;
            var _loc_4:* = GlobalStyle.textFormatBai.left();
            _loc_4.size = 14;
            while (_loc_6 < _loc_1.length)
            {
                
                _loc_3 = this._info[_loc_1[_loc_6]];
                if (_loc_3 > 0)
                {
                    _loc_2 = UIFactory.gTextField("", 53, 25 * _loc_5 + 15, 150, 30, this._privilegePart, _loc_4);
                    _loc_2.htmlText = MedalConfig.instance.translateValueName(_loc_1[_loc_6]) + _loc_3 + "%";
                    this._vcPrivilegeTxt.push(_loc_2);
                    _loc_5++;
                }
                _loc_6++;
            }
            this._noPrivilegeTxt.text = this._vcPrivilegeTxt.length == 0 ? (Language.getString(20813)) : ("");
            return;
        }// end function

    }
}
